package pers.dzk.fivelnarow.checkerboard;
import pers.dzk.fivelnarow.config.CheckerboardConfig;
import pers.dzk.fivelnarow.piece.NullPiece;
import pers.dzk.fivelnarow.piece.Piece;

import javax.swing.*;
import java.awt.*;
import java.io.Serializable;

/**
 * @author 丁泽凯
 * 棋盘
 */
public abstract class CheckerboardSuper implements Serializable {
    private Piece[][] pieceMatrix;
    //尝试把这个字段删掉
    private Point[][] pointMatrix;
    private Point start;
    private int lineCount = CheckerboardConfig.getLineCount();
    private int lineDistance = CheckerboardConfig.getLineDistance();
    private int width = CheckerboardConfig.getWidth();
    private int height = CheckerboardConfig.getHeight();
    private ImageIcon img = null;

    public Piece[][] getPieceMatrix() {
        return pieceMatrix;
    }

    public void setPieceMatrix(Piece[][] pieceMatrix) {
        this.pieceMatrix = pieceMatrix;
    }

    public Point[][] getPointMatrix() {
        return pointMatrix;
    }

    public void setPointMatrix(Point[][] pointMatrix) {
        this.pointMatrix = pointMatrix;
    }

    public Point getStart() {
        return start;
    }

    public void setStart(Point start) {
        this.start = start;
    }

    public int getLineCount() {
        return lineCount;
    }

    public void setLineCount(int lineCount) {
        this.lineCount = lineCount;
    }

    public int getLineDistance() {
        return lineDistance;
    }

    public void setLineDistance(int lineDistance) {
        this.lineDistance = lineDistance;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public ImageIcon getImg() {
        return img;
    }

    public void setImg(ImageIcon img) {
        this.img = img;
    }

    public CheckerboardSuper(){
        //初始化变量
        start = new Point((width -((lineCount -1)* lineDistance))/2,(height +((lineCount -1)* lineDistance))/2);
        pieceMatrix = new Piece[lineCount][lineCount];
        pointMatrix = new Point[lineCount][lineCount];
        for (int i = 0; i < lineCount; i++) {
            for (int j = 0; j < lineCount; j++) {
                pointMatrix[i][j] = new Point(start.x+ lineDistance *j, start.y- lineDistance *i);
                pieceMatrix[i][j] = new NullPiece(pointMatrix[i][j]);
            }
        }
    }
    public CheckerboardSuper(ImageIcon img){
        this();
        this.img = img;
    }
    /**
     * 初始化棋盘
     * @param jPanel
     */
    public abstract void initial(JPanel jPanel);
    /**
     * 绘画棋盘
     * @param g
     */
    public abstract void paintCheckerboard(Graphics2D g);
}
